import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class StudentManagementSystem {
    public static void main(String[] args) {
        // 启动应用程序的逻辑
        // 使用SwingUtilities在事件调度线程中创建和显示GUI
        SwingUtilities.invokeLater(() -> {
            createAndShowGUI();
        });
    }

    private static void createAndShowGUI() {
        // 创建主窗口
        JFrame frame = new JFrame("学生管理系统");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(400, 300);

        // 创建面板
        JPanel panel = new JPanel();
        panel.setLayout(new GridLayout(0, 1)); // 设置为垂直排列
        frame.getContentPane().add(panel);

        // 添加标签
        JLabel label = new JLabel("欢迎使用学生管理系统", JLabel.CENTER);
        panel.add(label);

        // 添加按钮
        JButton classManagementButton = new JButton("班级管理");
        classManagementButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new ClassManagement();
                ClassManagement.main(null); // 跳转到班级管理
            }
        });
        panel.add(classManagementButton);

        JButton groupManagementButton = new JButton("小组管理");
        groupManagementButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new GroupManagement();
                GroupManagement.main(null); // 跳转到小组管理
            }
        });
        panel.add(groupManagementButton);

        JButton studentManagementButton = new JButton("学生管理");
        studentManagementButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new StudentManagement();
                StudentManagement.main(null); // 跳转到学生管理
            }
        });
        panel.add(studentManagementButton);

        JButton randomSelectionButton = new JButton("随机点名");
        randomSelectionButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new RandomSelection();
                RandomSelection.main(null); // 跳转到随机点名
            }
        });
        panel.add(randomSelectionButton);

        // 显示窗口
        frame.setVisible(true);
    }
}
